const fs = require("fs");

// 1. 通过流读取文件
const readStream = fs.createReadStream("./stream-file/stream1.txt", {
  encoding: "utf-8",
  start: 0, // 从哪个位置开始读取
  end: 22, // 读取到哪个位置结束
  highWaterMark: 3, // 每次读取2个字节
});

// 1.1 监听流的data事件
readStream.on("data", (data) => {
  console.log(data.toString());
});

// 2. 监听流的开启和关闭
readStream.on("open", () => {
  console.log("流已经打开");
});

readStream.on("end", () => {
  console.log("流已经读取完毕");
});

readStream.on("close", () => {
  console.log("流已经关闭");
});
